<!--学生查看校内题目和选报校内题目-->
<style>
	.yanse {
		width: 20px;
		height: 20px;
		display: inline-block;
		line-height: 20px;
	}
	
	.input-group {
		margin-bottom: 20px;
	}
	
	.wenxintishi {
		margin-bottom: 20px;
	}
	
	.xiaofangkuai {
		display: inline-block;
	}
	
	#ketixinxi11 {
		height: 120px;
	}
	
	.bottom_10 {
		margin-bottom: 20px;
	}
	
	.cur {
		cursor: pointer;
	}
</style>

<h3 class="bottom_10">校内毕设选题</h3>
<table class="table table-striped table-bordered table-hover" id="table_">

</table>

<div class="tijiao">
	<button class="btn btn-primary disabled" disabled style="float: right;">提交选题</button>
</div>

<nav aria-label="...">
	<ul class="pager">
		<li>
			<a href="#" id="pre">上一页</a>
		</li>
		<li>
			<a href="#" id="top">首页</a>
		</li>
		<li>第<span class="num">1</span>页</li>
		<li>
			<a href="#" id="end">尾页</a>
		</li>
		<li>
			<a href="#" id="next">下一页</a>
		</li>
	</ul>
</nav>

<!-- 查看教师信息模态框 -->
<div class="modal fade" id="jiaoshixinxi" tabindex="-1" role="dialog" aria-labelledby="tianjiaketi1">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="jiaoshixinxi1">教师信息</h4>
			</div>
			<div class="modal-body">
				<div class="input-group">
					<span class="input-group-addon" id="jiaoshimingcheng">教师姓名</span>
					<input id="jiaoshixinming" type="text" class="form-control" aria-describedby="jiaoshimingcheng" readonly>
				</div>
				<div class="input-group">
					<span class="input-group-addon" id="zhuanyefangxiang">专业方向</span>
					<input id="" type="text" class="form-control" aria-describedby="zhuanyefangxiang" readonly>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
<!-- 查看毕设信息模态框 -->
<div class="modal fade" id="ketixinxi" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">毕设选题信息</h4>
			</div>
			<div class="modal-body">
				<div class="input-group">
					<span class="input-group-addon" id="ketimingcheng">毕设名称</span>
					<input id="ketimingcheng1" type="text" class="form-control" aria-describedby="ketimingcheng" readonly>
				</div>
				<div class="input-group">
					<span class="input-group-addon" id="ketixinxi1">毕设信息</span>
					<textarea class="form-control" type="text" id="ketixinxi11" aria-describedby="ketixinxi1" readonly></textarea>
				</div>
				<div class="input-group">
					<span class="input-group-addon" id="ketiyaoqiu">毕设要求</span>
					<textarea class="form-control" type="text" id="ketiyaoqiu1" aria-describedby="ketiyaoqiu" readonly></textarea>
				</div>
				<div class="input-group">
					<span class="input-group-addon" id="zhidaolaoshi">指导老师</span>
					<input id="zhidaolaoshi1" type="text" class="form-control" aria-describedby="zhidaolaoshi" readonly>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
<script>
	var pageSize = 15;
	var myajax;

	function charu(number) {
		var pageNum = number;
		myajax = $.ajax({ //一进入此页面先加载第一页内容
			xhrFields: {
				withCredentials: true
			},
			type: 'get',
			url: getFullURL('user/topic-list'),
			data: {
				pageNum: pageNum,
				pageSize: pageSize
			},
			dataType: 'json',
			success: function(data) {
				console.log(data)
				if(data.status == 0) {
					$(".tijiao button").addClass('disabled')
					$(".tijiao button").attr("disabled", true);

					$.session.set("prePageNum", data.page.prePageNum);
					$.session.set("nextPageNum", data.page.nextPageNum);
					$.session.set("totalPageNum", data.page.totalPageNum);
					$('.num').html(data.page.pageNum);
					$('#table_').html("");

					var table_one = `
                    	<tr>
                            <th col style="width: 25%">毕设名称</th>
                            <th col style="width: 30%">毕设信息</th>
                            <th col style="width: 30%">毕设要求</th>
                            <th col style="width: 10%">指导老师</th>
                            <th col style="width: 6%">选择</th>
                        </tr>
                    	`;
					var div_one = $(table_one);
					$('#table_').append(div_one);

					$.each(data.page.list, function(i, n) {
						var table_content = `
	                            <tr>
	                                <td class="cur" data-toggle="modal" data-target=""><label class="cur" for="` + n.gid + `">` + n.topic + `</label></td>
	                                <td class="cur" data-toggle="modal" data-target="">` + n.content + `</td>
	                                <td class="cur" data-toggle="modal" data-target="">` + n.demand + `</td>
	                                <td class="cur" data-toggle="modal" data-target="" value="` + n.tno + `">` + n.name + `</td>
	                                <td><input type="radio" class="keti cur" id="" value="` + n.gid + `"></td>
	                            </tr>
	                            `
						var div = $(table_content);
						$('#table_').append(div);
					})

					//
					$('#table_ tr').find('td:eq(0)').click(function() {
						$(this).attr('data-target', '#ketixinxi')
						$('#ketimingcheng1').attr('value', $(this).parent('tr').children('td').eq(0).text())
						$('#ketixinxi11').text($(this).parent('tr').children('td').eq(1).text())
						$('#ketiyaoqiu1').text($(this).parent('tr').children('td').eq(2).text())
						$('#zhidaolaoshi1').attr('value', $(this).parent('tr').children('td').eq(3).text())
					})
					$('#table_ tr').find('td:eq(1)').click(function() {
						$(this).attr('data-target', '#ketixinxi')
						$('#ketimingcheng1').attr('value', $(this).parent('tr').children('td').eq(0).text())
						$('#ketixinxi11').text($(this).parent('tr').children('td').eq(1).text())
						$('#ketiyaoqiu1').text($(this).parent('tr').children('td').eq(2).text())
						$('#zhidaolaoshi1').attr('value', $(this).parent('tr').children('td').eq(3).text())
					})
					$('#table_ tr').find('td:eq(2)').click(function() {
						$(this).attr('data-target', '#ketixinxi')
						$('#ketimingcheng1').attr('value', $(this).parent('tr').children('td').eq(0).text())
						$('#ketixinxi11').text($(this).parent('tr').children('td').eq(1).text())
						$('#ketiyaoqiu1').text($(this).parent('tr').children('td').eq(2).text())
						$('#zhidaolaoshi1').attr('value', $(this).parent('tr').children('td').eq(3).text())
					})
					$('#table_ tr').find('td:eq(3)').click(function() {
						$(this).attr('data-target', '#jiaoshixinxi')
						$('#jiaoshixinming').attr('value', $(this).parent('tr').children('td').eq(3).text())
					})

					$('.keti').change(function() {
						if($(this).attr('checked')) {
							$(".tijiao button").addClass('disabled') //按钮不可用
							$(".tijiao button").attr("disabled", true);
						} else {
							$(".keti").removeAttr("checked");
							$(this).prop("checked", true);
							$(".tijiao button").removeClass('disabled') //按钮可用
							$(".tijiao button").removeAttr("disabled");
						}
					})
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	}

	charu(1);

	$("#top").click(function() {
		charu(1);
	})

	$("#end").click(function() {
		charu($.session.get("totalPageNum"));
	})

	$("#pre").click(function() {
		charu($.session.get("prePageNum"));
	})

	$("#next").click(function() {
		charu($.session.get("nextPageNum"));
	})

	function put_gid() {
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: 'post',
			url: getFullURL('user/opt-topic'),
			data: {
				gid: $("input[type='radio']:checked").val()
			},
			dataType: 'json',
			success: function(data) {
				if(data.status == 0) {
					alert('提交成功！')
					$('.center').html('');
					$('.center').load('./studentlook.html');
				} else {
					alert('您已选报成功，请查看审核状态！')
					$('.center').html('');
					$('.center').load('./studentlook.html');
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	}

	function get_cost() {
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: 'get',
			url: getFullURL('user/get-cost'),
			data: {},
			dataType: 'json',
			success: function(data) {
				if(data.status == 0) {
					if(data.cost == 0) {
						put_gid()
					} else {
						alert("您的学费未缴纳完毕，请联系相关老师核查！");
						return;
					}
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	}

	$.when(myajax).done(function() {
		$('.tijiao button').click(function() {
			$.ajax({
				xhrFields: {
					withCredentials: true
				},
				type: 'get',
				url: getFullURL('user/bstp-status'),
				data: {},
				dataType: 'json',
				success: function(data) {
					console.log(data)
					if(data.bsStatus == -1 || data.bsStatus == 0) {
						get_cost()
					} else {
						alert('您已选报成功，请查看审核状态！')
						$('.center').html('');
						$('.center').load('./studentlook.html');
					}
				},
				error: function(err) {
					alert("请求异常，请重新登录！", function() {
						$(location).attr('href', './login.html');
					})
				}
			})
		})
	})
</script>